package com.woniu.job.service.impl;

import com.woniu.job.entity.ResponseVo;
import com.woniu.job.entity.User;
import com.woniu.job.mapper.UserMapper;
import com.woniu.job.service.IUserService;
import com.woniu.job.util.Helper;
import com.woniu.job.util.Utils;

import ch.qos.logback.classic.pattern.Util;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import javax.management.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author song
 * @since 2019-12-24
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

	@Autowired
	private ResponseVo vo;
	@Autowired
	private UserMapper userMapper;
	/**
	 * 注册
	 */
	@Override
	public ResponseVo register(User user) {
	
		if(userMapper.findUserByAcc(user)>0) {
			vo.setCode("500");
			vo.setMeg("账号已存在");
			return vo;
		}
		
		user.setId(Utils.getUID());
		user.setStatus("1");
		userMapper.insert(user);
		vo.setCode("200");
		vo.setMeg("注册成功");
		return vo;
	}
	/**
	 * 登录
	 */
	@Override
	public ResponseVo login(User user) {
		User userLogin=userMapper.findUserByAccAndPwd(user);
		if(userLogin==null) {
			
			vo.setCode("500");
			vo.setMeg("账号或密码错误");
		}else {
			vo.setCode("200");
			vo.setMeg("登录成功");
			vo.setData(userLogin); 
		}
		return vo;
	}
	/**
	 * 用户资料
	 */
	@Override
	public User findUser(User user) {
		return userMapper.findUserById(user);
	}
	/**
	 * 上传头像
	 */
	@Override
	public void updateAvater(User user) {
		userMapper.updateAvater(user);
		
	}
	/**
	 * 修改密码
	 */
	@Override
	public ResponseVo updatePwd(User user) {
		userMapper.updatePwdById(user);
		vo.setCode("200");
		vo.setMeg("修改成功");
		return vo;
	}
	/**
	 * 完善个人信息
	 */
	@Override
	public ResponseVo updateProfile(User user) {
		userMapper.updateProfile(user);
		vo.setCode("200");
		vo.setMeg("修改成功");
		return vo ;
	}

}
